<?php

require_once 'Ext/Session.php';

class Ext_Session
{
    const NAMESPACE_DEFAULT = 'Zend_Auth';

    const MEMBER_DEFAULT = 'userId';

    protected $_session;

    protected $_namespace;

    protected $_member;

    public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT)
    {
        $this->_namespace = $namespace;
        $this->_member    = $member;
        $this->_session   = new Zend_Session_Namespace($this->_namespace);
    }

    public function getNamespace()
    {
        return $this->_namespace;
    }

    public function getMember()
    {
        return $this->_member;
    }

    public function setMember($member)
    {
        $this->_member = $member;
        return $this;
    }
    
    public function getSession()
    {
        return $this->_session;
    }

    public function isEmpty()
    {
        return !isset($this->_session->{$this->_member});
    }

    public function read()
    {
        return $this->_session->{$this->_member};
    }

    public function write($contents)
    {
        $this->_session->{$this->_member} = $contents;
    }

    public function clear($member = null)
    {
        if($member === null){
            Zend_Session::namespaceUnset($this->_namespace);
        }else {
            unset($this->_session->{$member});
        }
    }

}
